<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        // 数组：有序存储多个元素的容器
        var arr = ['关羽', '张飞', '马超', '赵云'];
        console.log(arr[3]);
        // 数组名[index] 可以看作变量
        arr[3] = "貂蝉";

        // 1. 通过索引号，添加元素
        arr[4] = "剑圣";
        arr[6] = "盲僧";
        console.log(arr[5]);  // undefined 只声明为赋值的变量

        // 2. 修改数组的长度，添加元素
        arr.length = 10;

        console.log(arr[8], arr[9]);
        console.log(arr);

        // 新建一个数组，里面存放10个整数 1~10
        let arr1 = [];
        // arr1[0] = 1;
        // arr1[1] = 2;
        // arr1[9] = 10;
        for (let i = 0; i < 10; i++) {
            // console.log(i);
            arr1[i] = i + 1;
        }
        console.log(arr1);

    </script>
</head>

<body>

</body>

</html>